Overview
Thebulk_market_analyzer.py script is the primary processing engine of the ChartsMaze EDL Pipeline. It combines fundamental data, technical indicators, shareholding patterns, and market data to create a comprehensive analysis for all stocks in the dataset.
Purpose
This script processes raw fundamental and technical data to generate a unified analysis dataset containing:- Quarterly and annual financial metrics (P&L, Sales, EPS, OPM)
- Valuation ratios (P/E, ROE, ROCE, D/E, PEG)
- Shareholding patterns and institutional activity
- Technical indicators and price performance
- Advanced indicator signals (SMA/EMA positioning, RSI, MACD)
- Index membership and market classification
Input Files Required
Core fundamental data containing quarterly and annual financial statements, ratios, and company metadata.
Technical data including price, moving averages, RSI, volume, and index membership from Dhan API.
Advanced technical indicators including SMA/EMA arrays, oscillators, pivots, and trend signals. Script runs without this but with reduced technical analysis.
NSE equity listing information containing stock symbols and listing dates.
Output Produced
Comprehensive analysis file containing enriched data for all stocks. Each stock record includes fundamental metrics, technical indicators, and derived calculations.
Processing Logic
1. Data Loading
The script loads multiple data sources and creates lookup maps:2. Financial Metrics Extraction
The script extracts data from pipe-delimited strings representing time series:3. Growth Calculations
QoQ and YoY percentage changes are calculated for key metrics:4. Ratio Calculations
Derived financial ratios:5. Shareholding Analysis
6. Technical Indicators Processing
7. Advanced Indicators Parsing
Extracts signals from SMA/EMA arrays and technical indicators:8. Index Membership Mapping
Fields Added/Modified
This script creates the foundational dataset with the following field structure:Basic Information
- Symbol: Stock symbol
- Name: Company name
- Listing Date: Date of listing on exchange
- Basic Industry: Industry classification
- Sector: Sector classification
- Market Cap(Cr.): Market capitalization in crores
- Latest Quarter: Most recent financial quarter reported
Profitability Metrics
- Net Profit Latest Quarter to Net Profit 3 Quarters Back: Historical net profit
- QoQ % Net Profit Latest: Quarter-over-quarter net profit change
- YoY % Net Profit Latest: Year-over-year net profit change
EPS Metrics
- EPS Latest Quarter to EPS 3 Quarters Back: Quarterly EPS history
- QoQ % EPS Latest: Quarter-over-quarter EPS growth
- YoY % EPS Latest: Year-over-year EPS growth
- EPS Last Year: Full-year EPS from previous year
- EPS 2 Years Back: Full-year EPS from two years ago
Sales Metrics
- Sales Latest Quarter to Sales 3 Quarters Back: Quarterly sales
- QoQ % Sales Latest: Quarter-over-quarter sales growth
- YoY % Sales Latest: Year-over-year sales growth
- Sales Growth 5 Years(%): Compounded annual growth rate over 5 years
Margin Metrics
- OPM Latest Quarter to OPM 3 Quarters Back: Operating profit margin history
- QoQ % OPM Latest: Quarter-over-quarter OPM change
- YoY % OPM Latest: Year-over-year OPM change
- OPM TTM(%): Trailing twelve months operating profit margin
Valuation Ratios
- ROE(%): Return on equity
- ROCE(%): Return on capital employed
- D/E: Debt-to-equity ratio
- P/E: Price-to-earnings ratio
- PEG: Price/earnings-to-growth ratio
- Forward P/E: Forward-looking P/E based on annualized latest quarter EPS
Shareholding Pattern
- FII % change QoQ: Foreign institutional investor holding change
- DII % change QoQ: Domestic institutional investor holding change
- Free Float(%): Percentage of shares available for public trading
- Float Shares(Cr.): Free float shares in crores
Technical Indicators
- Stock Price(₹): Current market price
- Index: List of indices the stock belongs to
- 1 Day Returns(%) to 1 Year Returns(%): Historical returns
- RSI (14): 14-period Relative Strength Index
- % from 52W High: Distance from 52-week high
- SMA Status: Price positioning relative to SMA 20, 50, 200
- EMA Status: Price positioning relative to EMA 20, 50, 200
- Technical Sentiment: Aggregated signals from RSI, MACD
- Pivot Point: Classic pivot point value
- Gap Up %: Opening gap percentage (placeholder, updated by advanced processor)
Code Example
bulk_market_analyzer.py
Function Reference
get_float(value_str)
Safely converts string values to float.
Parameters:
value_str: String or numeric value to convert
calculate_change(current, previous)
Calculates percentage change between two values.
Parameters:
current: Current period valueprevious: Previous period value
get_value_from_pipe_string(pipe_string, index)
Extracts value from pipe-delimited time series string.
Parameters:
pipe_string: Pipe-delimited string (e.g., “100|95|90|85”)index: Zero-based position to extract
analyze_all_stocks()
Main processing function that orchestrates the entire analysis pipeline.
Returns: None (writes output to JSON file)
Performance Notes
- Processes ~2,000 stocks in approximately 5-10 seconds
- Memory usage scales with dataset size (typically 200-500 MB)
- No parallelization implemented; runs sequentially
- Can handle missing data sources gracefully with warnings
Dependencies
json: Standard library for JSON processingcsv: Standard library for CSV parsingos: File path operations
Source File Location
bulk_market_analyzer.py:1-360